package com.example.crystall_ball;

import knh.*;
import android.os.Bundle;
import android.app.Activity;
import android.view.*;
import android.widget.*;

public class MainActivity extends Activity {
	DB_Items dbi;
	DB_Groups dbg;
	EditText mText;
	boolean chk = true;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mText = (EditText)findViewById(R.id.InputText);
        dbi = new DB_Items(this);
        dbg = new DB_Groups(this);
    }

/*    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }*/
    
    public void m0nClick(View v){
    	
    	switch(v.getId()){
    	case R.id.Save:
    		dbi.SaveData(new Item("1013","필통",1));
    		if(!dbi.SaveData(new Item("2012","C프로그래밍",1))){
    			mText.setText("입력에 실패하였습니다.");
    			break;
    		}
    		dbi.SaveData(new Item("33ab6","지갑",3));
    		dbg.SaveData(new CheckList_Data(1,"학과수업","1013,2012"));
    		dbg.SaveData(new CheckList_Data(3,"ㅁㄴㅇㄹ","2012,33ab6"));
    		dbg.SaveData(new CheckList_Data(4,"qwerty","1013,33ab6"));
    		mText.setText("입력완료!");
    		break;
    	case R.id.Load:
    		CheckList_Data group = dbg.LoadData("학과수업");
    		String text = group.getGroupNum()+" : "+group.getName()+" : ";
    		for(String t:group.getTagID()){
    			text += t + " ";
    		}
    		mText.setText(text);
    		/*
    		Item item = dbi.LoadData("1013");
    		if(item.getId()=="-1"){
    			mText.setText("일치하는id가 없습니다.");
    		}else{
    			mText.setText(item.getId()+":"+item.getName()+":"+Integer.toString(item.getIcon()));
    		}*/
    		break;
    	case R.id.Delete:
    		dbg.DeleteData(1);
    		mText.setText("삭제완료!");
    		break;
    	case R.id.LoadAll:
    		CheckList_Data[] groups = new CheckList_Data[dbg.getGroup_Limit()];
    		groups = dbg.LoadAllData();
    		String texts[] = new String[3];
    		if(chk){
	    		texts[0] = groups[0].getGroupNum() + ":" + groups[0].getName()+":"+groups[0].getTagIDbyString();
	    		texts[1] = groups[1].getGroupNum() + ":" + groups[1].getName()+":"+groups[1].getTagIDbyString();
	    		texts[2] = groups[2].getGroupNum() + ":" + groups[2].getName()+":"+groups[2].getTagIDbyString();
	    		mText.setText(texts[0]+" / "+texts[1]+" / "+texts[2]);
	    		chk = false;
    		}else{
    			texts[0] = groups[0].getGroupNum() + ":" + groups[0].getName()+":"+groups[0].getTagIDbyString();
	    		texts[1] = groups[1].getGroupNum() + ":" + groups[1].getName()+":"+groups[1].getTagIDbyString();
	    		mText.setText(texts[0]+" / "+texts[1]);
    		}
    		/*
    		Item items[] = new Item[dbi.getItem_Limit()];
    		items = dbi.LoadAllData();
    		
    		String texts[] = new String[100];
    		texts[0] = new String(items[0].getId()+":"+items[0].getName()+":"+Integer.toString(items[0].getIcon())+"--");
    		texts[1] = new String(items[1].getId()+":"+items[1].getName()+":"+Integer.toString(items[1].getIcon())+"--");
    		texts[2] = new String(items[2].getId()+":"+items[2].getName()+":"+Integer.toString(items[2].getIcon())+"--");
    		
    		mText.setText(texts[0]+texts[1]+texts[2]);*/
    		break;
    	}
    }
    
    protected void finalize(){
    	dbi.DeleteAllData();
    	dbg.DeleteAllData();
    }
}
